<template>
  <div class="container-box">
    <van-nav-bar fixed>
      <!-- 显示定位 -->
      <template #left>
        <van-icon name="arrow-left" @click="onClickLeft" />
      </template>
      <!-- 查询 -->
      <template #title>
        <p class="search">
          <van-icon name="search" />
          <span>搜索</span>
        </p>
      </template>
      <!-- 个人中心 -->
      <template #right>
        <van-icon v-if="change" name="apps-o" @click="changeFn" />
        <van-icon v-else name="bars" @click="changeFn" />
      </template>
    </van-nav-bar>
    <!-- tab切换栏 -->
    <!-- <van-icon name="filter-o" />筛选 -->
    <van-tabs v-model="active">
      <van-tab title="人气"></van-tab>
      <van-tab title="销量"></van-tab>
      <van-tab>
        <template #title>
          <div class="tabBox" @click="sortFn">
            <span>价格</span>
            <van-icon name="descending" v-if="sortFlag" />
            <van-icon name="ascending" v-else />
          </div>
        </template>
      </van-tab>
      <van-tab>
        <template #title>
          <div class="tabBox" @click="screenFn">
            <span>筛选</span>
            <van-icon name="filter-o" class="newIcon" />
          </div>
        </template>
      </van-tab>
    </van-tabs>
    <div class="list" :class="change ? 'list-vertical' : 'list-col-2'">
      <div
        class="card"
        v-for="item in showData"
        :key="item.id"
        @click="jumpDetails"
      >
        <van-image :src="item.img" />
        <div class="content">
          <div class="title text-overflow">{{ item.title }}</div>
          <div class="des">{{ item.des }}</div>

          <div class="price">
            <span><i>￥</i>{{ item.price }}</span>
          </div>

          <div class="info">
            <span class="fl">{{ item.info }}人购买</span>
          </div>
        </div>
      </div>
    </div>
    <!-- 筛选弹出框 -->
    <van-popup
      v-model="show"
      position="right"
      :style="{ width: '90%', height: '100%', backgroundColor: ' #f5f5f5' }"
    >
      <Screen @cancel="cancel"></Screen>
    </van-popup>
  </div>
</template>

<script>
import Screen from './components/Screen/Screen.vue'
export default {
  components: {
    Screen
  },
  data() {
    return {
      show: false,
      change: true,
      active: 1,
      sortFlag: true,
      showData: [
        {
          id: 1,
          img: 'https://img.dangaoss.com/public/p/18/10/1341963_l.jpg',
          title: '蓝莓之夜',
          des:
            '蜜时cake | 新鲜的沃佳蓝莓和法国红加仑软软的落在蛋糕上，英国蓝米吉淡奶油与法国宝茸蓝莓果茸融合，在蓝莓的酸甜中混入柔和的奶味儿，香草味的蛋糕胚为层次增加满足实在的口感。',
          price: '1681.00',
          info: '1678'
        },
        {
          id: 2,
          img: 'https://img.dangaoss.com/public/p/18/10/1341963_l.jpg',
          title: '蓝莓之夜',
          des:
            '蜜时cake | 新鲜的沃佳蓝莓和法国红加仑软软的落在蛋糕上，英国蓝米吉淡奶油与法国宝茸蓝莓果茸融合，在蓝莓的酸甜中混入柔和的奶味儿，香草味的蛋糕胚为层次增加满足实在的口感。',
          price: '162.00',
          info: '1678'
        },
        {
          id: 3,
          img: 'https://img.dangaoss.com/public/p/18/10/1341963_l.jpg',
          title: '蓝莓之夜',
          des:
            '蜜时cake | 新鲜的沃佳蓝莓和法国红加仑软软的落在蛋糕上，英国蓝米吉淡奶油与法国宝茸蓝莓果茸融合，在蓝莓的酸甜中混入柔和的奶味儿，香草味的蛋糕胚为层次增加满足实在的口感。',
          price: '156.00',
          info: '1678'
        },
        {
          id: 4,
          img: 'https://img.dangaoss.com/public/p/18/10/1341963_l.jpg',
          title: '蓝莓之夜',
          des:
            '蜜时cake | 新鲜的沃佳蓝莓和法国红加仑软软的落在蛋糕上，英国蓝米吉淡奶油与法国宝茸蓝莓果茸融合，在蓝莓的酸甜中混入柔和的奶味儿，香草味的蛋糕胚为层次增加满足实在的口感。',
          price: '198.00',
          info: '1678'
        },
        {
          id: 5,
          img: 'https://img.dangaoss.com/public/p/18/10/1341963_l.jpg',
          title: '蓝莓之夜',
          des:
            '蜜时cake | 新鲜的沃佳蓝莓和法国红加仑软软的落在蛋糕上，英国蓝米吉淡奶油与法国宝茸蓝莓果茸融合，在蓝莓的酸甜中混入柔和的奶味儿，香草味的蛋糕胚为层次增加满足实在的口感。',
          price: '110.00',
          info: '1678'
        },
        {
          id: 6,
          img: 'https://img.dangaoss.com/public/p/18/10/1341963_l.jpg',
          title: '蓝莓之夜',
          des:
            '蜜时cake | 新鲜的沃佳蓝莓和法国红加仑软软的落在蛋糕上，英国蓝米吉淡奶油与法国宝茸蓝莓果茸融合，在蓝莓的酸甜中混入柔和的奶味儿，香草味的蛋糕胚为层次增加满足实在的口感。',
          price: '123.00',
          info: '1678'
        }
      ]
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    changeFn() {
      this.change = !this.change
    },
    sortFn() {
      // 排序
      this.sortFlag = !this.sortFlag
      function sortD(a, b) {
        return a.price - b.price
      }
      function sortU(a, b) {
        return b.price - a.price
      }
      if (this.sortFlag) {
        this.showData = this.showData.sort(sortD)
      } else {
        this.showData = this.showData.sort(sortU)
      }
    },
    screenFn() {
      // 筛选
      this.show = true
    },
    cancel() {
      //  取消弹窗
      this.show = false
    },
    jumpDetails() {
      // 跳转商品详情
      this.$router.push('/GoodsDetails')
    }
  }
}
</script>

<style lang="less" scoped>
.van-nav-bar {
  .van-icon {
    font-size: 0.35rem;
    color: #ff4463;
  }
  .search {
    width: 60vw;
    background-color: #f0f0f0;
    color: #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4px;
    border-radius: 10vw;
    font-size: 14px;
    font-weight: normal;

    i {
      color: #ccc !important;
      margin-right: 5px;
      font-size: 20px;
    }
  }
}
.container-box {
  background-color: #f5f5f5;
  padding-top: 90px;
  height: 100%;
  .van-tabs {
    width: 100%;
    position: fixed;
    top: 45px;
    left: 0;
    z-index: 999;
    border-top: 1px solid #eaeaea;
    border-bottom: 1px solid #eaeaea;
    /deep/.van-tab--active {
      color: #ff4463;
    }
    /deep/.van-tabs__line {
      background-color: #ff4463;
      height: 2px;
    }
    /deep/.van-tab {
      .van-tab__text {
        .tabBox {
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
      .van-icon {
        font-size: 0.3rem;
        color: #ff4463;
        margin-left: 0.1rem;
      }
      .newIcon {
        font-size: 0.28rem;
      }
    }
  }
  // 正常列表展示
  .list-vertical {
    background-color: #fff;
    .card {
      font-size: 0;
      padding: 0.3rem 0;
      border-bottom: 1px solid #efefef;
      display: flex;
      .van-image {
        width: 25%;
        border: 1px solid #efefef;
        margin-left: 4%;
      }
      .content {
        width: 67%;
        margin-left: 4%;
        font-size: 0.3rem;
        display: inline-block;
        vertical-align: middle;
        .title,
        .des {
          padding-right: 0.2rem;
          -webkit-box-sizing: border-box;
          -moz-box-sizing: border-box;
          -ms-box-sizing: border-box;
          -o-box-sizing: border-box;
          box-sizing: border-box;
        }
        .text-overflow {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          word-wrap: normal;
        }
        .des {
          color: #6d6d6d;
          font-size: 0.25rem;
          overflow: hidden;
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .price {
          margin-top: 0.3rem;
          font-weight: normal;
          color: #ff4463;
          i {
            font-style: normal;
            margin: 0 -0.02rem;
          }
        }
        .info {
          overflow: hidden;
          color: #6d6d6d;
          font-size: 0.25rem;
          .fl {
            float: left;
          }
        }
      }
    }
  }
  // 大图展示
  .list-col-2 {
    background-color: #fff;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 0.2rem 0.2rem 0 0.2rem;
    .card {
      width: 49%;
      padding-bottom: 0.2rem;
      margin-bottom: 0.2rem;
      cursor: pointer;
      border: 1px solid #e0e0e0;
      box-sizing: border-box;
      &:nth-child(2n + 1) {
        margin-right: 2%;
        margin-top: 0;
      }
      .van-image {
        display: block;
        width: 100%;
      }
      .content {
        margin-top: 0.2rem;
        color: #494949;
        padding: 0 0.2rem;
        font-size: 0.3rem;
        box-sizing: border-box;
        overflow: hidden;
        .title,
        .des {
          padding-right: 0.2rem;
          box-sizing: border-box;
        }
        .des {
          color: #6d6d6d;
          font-size: 0.25rem;
          overflow: hidden;
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .price {
          margin-top: 0.1rem;
          font-weight: normal;
          color: #ff4463;
          i {
            font-style: normal;
            margin: 0 -0.02rem;
          }
        }
        .info {
          overflow: hidden;
          color: #6d6d6d;
          font-size: 0.25rem;
          .fl {
            float: left;
          }
        }
      }
    }
  }
}
</style>
